/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package taskmanager2ndedition;

import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.List;
import org.xml.sax.InputSource;

/**
 *
 * @author Александр
 */
public class Cmd {
    private String method;
    
    private List<Object> params;
    
    public Cmd(){
        method = null;
        params = null;
    }
    
    public Cmd(String method, List params){
        this.method = method;
        this.params = params;
    }

    /**
     * @return the method
     */
    public String getMethod() {
        return method;
    }

    /**
     * @param method the method to set
     */
    public void setMethod(String method) {
        this.method = method;
    }

    /**
     * @return the params
     */
    public List getParams() {
        return params;
    }

    /**
     * @param params the params to set
     */
    public void setParams(List params) {
        this.params = params;
    }
    
    public static String toString(Cmd value)
    {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        XMLEncoder encoder = new XMLEncoder(outputStream);
        encoder.writeObject(value);
        encoder.flush();
        encoder.close();
        return outputStream.toString();
    }
    
    public static Cmd fromString(String value)
    {
        InputSource source = new InputSource(new StringReader(value)); 
        XMLDecoder decoder = new XMLDecoder(source);
        Cmd cmd = (Cmd)decoder.readObject();
        return cmd;
    }
}
